from AudioFiles import AudioFiles
from DownloadFile import DownloadFile
from pathlib import Path


def main():
    url = input("Enter the URL: ")

    # url = 'https://www.pep.com.cn/zslth/yyptypzj/xypep/3s/'
    af=AudioFiles(url)
    af.getHtml()

    dfile=DownloadFile()
    basePath=dfile.createPath('data')

    for t in af.audios:
        title=t['title']
        audios=t['audios']
        folder= dfile.createPath(basePath.joinpath(title))

        for audio in audios:
            url=audio['src']
            filename=audio['name']
            dfile.download_mp3(url,folder.joinpath(filename+'.mp3'))
            print(f"Downloaded {filename}")

while True:
    main()